#include <iostream>

using namespace std;
const int M = 30010, N =30;
int n, m;
int v[M], p[M];
int f[N];

int main()
{
	cin >> m >> n;
	for (int i = 1; i <= n; i++) cin >> v[i] >> p[i];

	for (int i = 1; i <= n; i++)
		for (int j = m; j >= v[i]; j--)
			f[j] = max(f[j], f[j - v[i]] + p[i] * v[i]);

	cout << f[m] << endl;
	return 0;
}